/**
 * MenuFrameChooseHomeStar.java
 *
 * Roslan's Remake of MOO in 3D using Ardor3D
 * (C) 2011 Roslan Amir. All rights reserved.
 */

package com.roslan.games.moo3d.ui.menu;

import com.ardor3d.extension.ui.UIButton;
import com.ardor3d.extension.ui.UILabel;
import com.ardor3d.extension.ui.UIPanel;
import com.ardor3d.extension.ui.UITextField;
import com.ardor3d.extension.ui.event.ActionEvent;
import com.ardor3d.extension.ui.event.ActionListener;
import com.ardor3d.extension.ui.layout.GridLayoutData;
import com.ardor3d.extension.ui.layout.RowLayout;
import com.roslan.games.moo3d.GameData.Actions;
import com.roslan.games.moo3d.data.Star;

/**
 * Comments go here.
 * 
 * @author Roslan Amir
 * @version 1.0 - Jan 27, 2011
 */
public class MenuFrameChooseHomeStar extends MenuFrameBase {

	/**
	 * Default no-arg constructor.
	 */
	public MenuFrameChooseHomeStar() {
		super("Choose Home Star");

		/*
		 * Panel with a vertical layout
		 */
		final UIPanel vpanel1 = new UIPanel();
		vpanel1.setLayout(new RowLayout(false));
		vpanel1.setMargin(FRAME_MARGINS);
		vpanel1.setBorder(SOLID_BORDER);
		vpanel.add(vpanel1);

		/*
		 * Text Label
		 */
		final UILabel chooseHomeStarLabel = new UILabel("[b]Your Home Star...[/b]");
		chooseHomeStarLabel.setStyledText(true);
		vpanel1.add(chooseHomeStarLabel);

		/*
		 * Text Entry Field
		 */
		final UITextField chooseHomeStarTextField = new UITextField();
		vpanel1.add(chooseHomeStarTextField);

		/*
		 * Panel with a horizontal layout
		 */
		final UIPanel hpanel = new UIPanel();
		hpanel.setLayout(new RowLayout(true));
		hpanel.setBorder(SOLID_BORDER);
		vpanel.add(hpanel);

		/*
		 * Back button
		 */
		final UIButton backButton = new UIButton("[b]Back[/b]");
		backButton.setStyledText(true);
		backButton.setLayoutData(new GridLayoutData(1, false, true));
		backButton.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent event) {
				gameData.action = Actions.SHOW_CHOOSE_LEADER_NAME_MENU;
			}
		});
		hpanel.add(backButton);

		/*
		 * Continue button
		 */
		final UIButton continueButton = new UIButton("[b]Continue[/b]");
		continueButton.setStyledText(true);
		continueButton.setLayoutData(new GridLayoutData(1, true, true));
		continueButton.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent event) {
				gameData.homeStarName = chooseHomeStarTextField.getText();
				gameData.action = Actions.START_GAME;
			}
		});
		hpanel.add(continueButton);

		/*
		 * Finalization
		 */
		this.setName("Choose Home Star");
		this.setContentPanel(vpanel);
		super.setUpFrame();
	}

	/**
	 * Update the contents of this frame before showing it.
	 */
	public void update() {
		UIPanel vpanel = this.getContentPanel();

		UIPanel vpanel1 = (UIPanel) vpanel.getChild(0);
		UITextField chooseHomeStarTextField = (UITextField) vpanel1.getChild(1);
		if (gameData.homeStarName == null || gameData.homeStarName.length() == 0) {
			gameData.homeStarName = Star.STAR_NAMES[gameData.playerRaceIndex + 1];
		}
		chooseHomeStarTextField.setText(gameData.homeStarName);
	}

}
